/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.artic.ogre.handler;

import com.artic.jme3.asset.plugins.ZipReLocator;
import com.artic.ogre.model.ResourceGroup;
import com.artic.ogre.model.ResourceLocation;
import com.artic.ogre.model.Scene;
import com.jme3.asset.AssetManager;
import com.jme3.asset.plugins.ZipLocator;
import com.jme3.scene.Node;

/**
 *
 * @author czarnik_a
 */
public class ResourceHandler implements ISceneHandler {

    private ISceneHandler nextHandler;
    private AssetManager assetManager;
    private Scene scene;
    private Node node;

    public void setNext(ISceneHandler handler) {
        nextHandler = handler;
    }

    public void handleScene(Scene scene, Node node, AssetManager assetManager) {
        this.assetManager = assetManager;
        this.scene = scene;
        this.node = node;
        registerResources();
        if (nextHandler != null) {
            nextHandler.handleScene(scene, node, assetManager);
        }
    }

    public void registerResources() {
        if (scene.getResourceGroup() != null) {
            ResourceGroup resourceGroup = scene.getResourceGroup();
            for (ResourceLocation resourceLocation : resourceGroup.getResourceLocation()) {
                switch (resourceLocation.getType()) {
                    case ZIP:
                        assetManager.registerLocator(resourceLocation.getValue(), ZipReLocator.class.getName());
                        break;
                }

            }
        }
    }
}
